import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import zy from '@/components/zy'
import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import pics_list from '@/components/pics_list'
import addpics from '@/components/addpics'
import changepics from '@/components/changepics'
import addgoods from '@/components/addgoods'
import editgood from '@/components/editgood'
import search from '@/components/search'






Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/zy',
          name:'zy',
          component:zy
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        //拦截器的使用
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter: (to, from, next) => {
            //判断用户是否登录
            if(localStorage.getItem("username")){
              // console.log("已登录");
              next();
            }else{
              // console.log("未登录");
              next('/login')
            }
          }
        },
        {
          path:'/pics_list',
          name:'pics_list',
          component:pics_list
        },  
        {
          path:'/addpics',
          name:'addpics',
          component:addpics
        },  
        {
          path:'/changepics',
          name:'changepics',
          component:changepics
        },  
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },  
        {
          path:'/editgood',
          name:'editgood',
          component:editgood
        },  
        {
          path:'/search',
          name:'search',
          component:search
        },  
  
        
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
